##=============================================================================
## Appendix Figure 11
##=============================================================================

##-----------------
# clear environment
rm(list=ls())
options(stringsAsFactors = FALSE, scipen = 999)
# source("R/functions.R")

seed <- sample.int(.Machine$integer.max, 1)
set.seed(seed)

ipak <- function(pkg){new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
if(length(new.pkg)) install.packages(new.pkg, dependencies = TRUE)
sapply(pkg, require, character.only = TRUE)
}

packages <- c("tidyverse", "hrbrthemes")

ipak(packages)

##---------
# Load data
#setwd("/Users/austinknuppe/Library/CloudStorage/Dropbox/Ukraine2022WartimeSurvey/Paper_peace/final_version_oct_2024/replication-scripts")
load("clean_ukraine_data.RData")

plot <- dat %>% 
  drop_na(save_lives) %>% 
  mutate(wave = factor(wave, labels = c("July 2022 \n (n = 1,830)", 
                                        "February 2023 \n (n = 1,838)"))) %>% 
  mutate(save_lives = factor(save_lives, 
                             labels = c("Much more important to \nkeep territory than \n to save lives",
                                        "Somewhat more important \n to keep territory than \n to save lives",
                                        "Somewhat more important to \n save lives than \n  to keep territory",
                                        "Much more important to \n save lives than \n to keep territory"))) %>% 
  group_by(wave, save_lives) %>% 
  summarise(n = n()) %>%
  mutate(freq = n / sum(n))

ggplot(plot, aes(x = save_lives, y = freq, fill = wave)) + 
  geom_bar(stat = "identity", position = position_dodge()) +
  labs(x = "", y = "Proportion", fill = "Wave") +
  scale_y_continuous(labels = scales::percent) +
  scale_fill_grey() +
  theme_bw(base_size = 20) +
  theme(legend.position = "bottom", 
        legend.direction = "horizontal",
        legend.text = element_text(size = 18))

rm(list = ls())
##=============================================================================
## End of File
##=============================================================================